<template>
    <div class="send-msg-main">
      <el-row class="row-test">
        <!--<el-button round>圆角按钮</el-button> danger warning info-->
        <el-button type="primary" round @click="send2Main('hide')">
          向主进程发送消息隐藏窗口,5秒后显示窗口
        </el-button>
        <el-button type="success" round @click="send2Main('close')">
          向主进程发送消息==>关闭窗口
        </el-button>
      </el-row>
      <el-row class="row-test">
        <!--<el-button round>圆角按钮</el-button>-->
        <el-button type="warning" round @click="backHome">
          返回首页
        </el-button>
      </el-row>
    </div>
</template>

<script>
const { ipcRenderer } = require('electron')

export default {
  name: 'sendMsg',
  methods: {
    send2Main (sendMag) {
      // console.log('aaaaaaaaaaaaaaaaaaaaaaa')
      // prints "pong"
      // console.log('ipcRenderer ==> ', ipcRenderer.sendSync('synchronous-message', 'ping'))
      let msg = ipcRenderer.sendSync('synchronous-message', sendMag)
      console.log('我是子进程,接收到消息了===>', msg)
      // ipcRenderer.on('asynchronous-reply', (event, arg) => {
      //   console.log(arg) // prints "pong"
      // })
      // require('electron').ipcRenderer.send('hideWindow')
      // 注意==>主进程console.log消息会显示在命令窗口
      setTimeout(() => {
        ipcRenderer.sendSync('synchronous-message', 'show')
      }, 5000)
    },
    backHome () {
      this.$router.replace('/')
    }
  }
}
</script>

<style lang="scss" scoped>
  .send-msg-main {
    width: 100%;
    height: 100%;
    .row-test {
      height: 100px;
    }
  }
</style>
